package com.exam.hellohass.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JsoupThreadForTitle {

	static String divcontent = "";
	static String divcontent_1 = "";
	static String content_0 = "";
	
	static String divcontent_2 = "";
	static String divcontent_3 = "";

	public static String getTitle(String url) {
		String title = "";
		String abs = url;

		try {
			Document doc = Jsoup.connect(url).data("jquery", "java")
					.userAgent("hellohass").cookie("auth", "token")
					.timeout(50000).get();
			content_0 = doc.toString();
			
			Document doc1 = Jsoup.parse(content_0);
			Elements divcon = doc1.getElementsByClass("ep-content-main");
			divcontent = divcon.toString();
			
			Document doc2 = Jsoup.parse(divcontent);
			Elements divcon_1 = doc2.getElementsByTag("h1");
			for (Element element : divcon_1) {
				title = element.text();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return title;
	}
	
	public static List<String> getContent(String url) {
		String content = "";
		String abs = url;

		List<String> contentList = new ArrayList<String>();
		try {
			Document doc = Jsoup.connect(url).data("jquery", "java")
					.userAgent("hellohass").cookie("auth", "token")
					.timeout(50000).get();
			divcontent_3 = doc.toString();
			
			Document doc1 = Jsoup.parse(divcontent_3);
//			Elements divcon = doc1.getElementsByClass("bd");
			Elements divcon = doc1.getElementsByClass("end-text");
			divcontent_2 = divcon.toString();
			
			Document doc2 = Jsoup.parse(divcontent_2);
			Elements divcon_1 = doc2.getElementsByTag("p");
			for (Element element : divcon_1) {
				content = element.text();
				contentList.add(content);
				content = element.getElementsByTag("img").attr("src").toString();
				contentList.add(content);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return contentList;
	}
	
}
